import 'package:boss/ui/widget/search_bar.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';

class CategoriesSearchBar extends StatefulWidget {
  final ValueChanged<String> onEditingComplete;
  final ValueChanged<String> onChanged;
  final bool enabled;
  final TextEditingController controller;

  const CategoriesSearchBar({
    Key key,
    this.onEditingComplete,
    this.enabled,
    this.onChanged,
    this.controller,
  }) : super(key: key);

  @override
  _CategoriesSearchBarState createState() => _CategoriesSearchBarState();
}

class _CategoriesSearchBarState extends State<CategoriesSearchBar> {
  String _value;

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.all(
        30.w,
      ),
      child: SearchBar(
        hintText: '输入需要查询的菜品名',
        controller: widget.controller,
        onChanged: (value) {
          _value = value;
          if (widget.onChanged != null) {
            widget.onChanged(value);
          }
        },
        onEditingComplete: () {
          if (widget.onEditingComplete != null) {
            widget.onEditingComplete(_value);
          }
        },
        enabled: widget.enabled,
      ),
    );
  }
}
